package com.solarfridge.monitor.shared.data;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable
public class FridgeData implements IsSerializable {

	/**
	 * The primary key for DataEntry objects.
	 * Should be the fridgeId concatenated with
	 * the timestamp
	 */
	@SuppressWarnings("unused")
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	private String encodedKey;
	/** Fridge Id */
	@Persistent
	private String mFridgeId;
	/** Ambient Ttempterature */
	@Persistent
	private double mATemp;
	/** Collector temperature */
	@Persistent
	private double mCTemp;
	/** Fridge temperature */
	@Persistent
	private double mFTemp;
	/** Collector sun intensity */
	@Persistent
	private double mCSun;
	/** Timestamp */
	@Persistent
	private long mTimeStamp;

	@SuppressWarnings("unused")
	private FridgeData(){
		mFridgeId = null;
		mATemp = -1;
		mCTemp = -1;
		mFTemp = -1;
		mCSun = -1;
		mTimeStamp = -1;
	}

	public FridgeData(String fridgeId, double aTemp, double cTemp,
			double fTemp, double cSun, long timeStamp) {
		mFridgeId = fridgeId;
		mATemp = aTemp;
		mCTemp = cTemp;
		mFTemp = fTemp;
		mCSun = cSun;
		mTimeStamp = timeStamp;
	}

	/**
	 * Determines if the data is valid, ie non null and no impossoble
	 * values, ie time = -1
	 * @return
	 */
	public boolean isValid(){
		return (mFridgeId != null &&
				mTimeStamp != -1);
	}

	public String getFridgeId() {
		return mFridgeId;
	}
	public double getATemp() {
		return mATemp;
	}
	public double getCTemp() {
		return mCTemp;
	}
	public double getFTemp() {
		return mFTemp;
	}
	public double getCSun() {
		return mCSun;
	}
	public long getTimeStamp() {
		return mTimeStamp;
	}
}
